﻿@using SmartStore.PayPal;
@using SmartStore.PayPal.Models;
@using SmartStore.Web.Framework;
@using SmartStore.Web.Framework.UI;
@model PayPalPlusConfigurationModel
@{
	Layout = "";
	Html.AddCssFileParts(true, "~/Plugins/SmartStore.PayPal/Content/smartstore.paypal.css");

	var hasCredentials = (Model.ClientId.HasValue() && Model.Secret.HasValue());
}

<div class="plugin-actions">
	<button type="submit" name="save" class="btn btn-warning" value="save">
		<i class="fa fa-check"></i>
		<span>@T("Admin.Common.Save")</span>
	</button>
</div>

<div class="plugin-configuration">
	<div>
		<div class="alert alert-info alert-dismissible">
			@Html.Raw(T("Plugins.Payments.PayPalPlus.AdminInstruction"))
			<button type="button" class="close" data-dismiss="alert">&times;</button>
		</div>
	</div>
	<div>
		<a href="https://www.paypal.de/paypal-plus" target="_blank">
			<img src="@Url.Content("~/Plugins/SmartStore.PayPal/Content/branding.png")" alt="PayPal" />
		</a>
	</div>
</div>

@{ Html.RenderAction("StoreScopeConfiguration", "Setting", new { area = "Admin" }); }

@Html.ValidationSummary(false)

@using (Html.BeginForm())
{
	@Html.HiddenFor(model => model.TransactMode)

    <table class="adminContent configure-paypal-plus">
		<tr>
			<td colspan="2">
				<div class="admin-config-group">
					<div class="title">
						@Model.ConfigGroups.SafeGet(0)
					</div>
				</div>
			</td>
		</tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.UseSandbox)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.UseSandbox)
                @Html.ValidationMessageFor(model => model.UseSandbox)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.ClientId)
            </td>
            <td class="adminData">
                @Html.SettingEditorFor(model => model.ClientId)
                @Html.ValidationMessageFor(model => model.ClientId)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.Secret)
            </td>
            <td class="adminData">
                @Html.SettingEditorFor(model => model.Secret)
                @Html.ValidationMessageFor(model => model.Secret)
            </td>
        </tr>
		<tr class="adminSeparator">
			<td colspan="2">
				<div class="admin-config-group">
					<div class="title">
						@Model.ConfigGroups.SafeGet(1)
					</div>
				</div>
			</td>
		</tr>
		<tr>
			<td class="adminTitle">
				@Html.SmartLabelFor(model => model.ExperienceProfileId)
			</td>
			<td class="adminData">
				@Html.SettingEditorFor(model => model.ExperienceProfileId)

				<a class="btn @(Model.ExperienceProfileId.HasValue() ? "btn-warning" : "btn-primary") mt-1" 
				   onclick='return confirm(@T("Admin.Common.AskToProceed").JsText);' @(hasCredentials ? "" : "disabled='disabled'")
				   href="@Url.Action("UpsertExperienceProfile", "PayPalPlus", new { area = Plugin.SystemName })">
					<i class="fa-fw @(Model.ExperienceProfileId.HasValue() ? "fa fa-sync" : "far fa-list-alt")"></i>
					<span>@T(Model.ExperienceProfileId.HasValue() ? "Common.Refresh" : "Common.AddNew")</span>
				</a>

				@if (Model.ExperienceProfileId.HasValue())
				{
					<a class="btn btn-danger mt-1" onclick='return confirm(@T("Admin.Common.AreYouSure").JsText);' @(hasCredentials ? "" : "disabled='disabled'")
					   href="@Url.Action("DeleteExperienceProfile", "PayPalPlus", new { area = Plugin.SystemName })">
						<i class="far fa-trash-alt"></i>
						<span>@T("Admin.Common.Delete")</span>
					</a>
				}

				@Html.ValidationMessageFor(model => model.ExperienceProfileId)
			</td>
		</tr>
		<tr>
			<td class="adminTitle">
				@Html.SmartLabelFor(model => model.WebhookId)
			</td>
			<td class="adminData">
				<div class="input-group">
					@* IPNs and webhook messages have no store context, so multistore configuration not possible here *@
					@Html.EditorFor(model => model.WebhookId)

					<div class="input-group-append">
						@if (Model.WebhookId.HasValue())
						{
							<a class="btn btn-danger" onclick='return confirm(@T("Admin.Common.AreYouSure").JsText);' @(hasCredentials ? "" : "disabled='disabled'")
							   href="@Url.Action("DeleteWebhook", "PayPalPlus", new { area = Plugin.SystemName })">
								<i class="far fa-trash-alt"></i>
								<span>@T("Admin.Common.Delete")</span>
							</a>
						}
						else
						{
							<a class="btn btn-primary btn-primary-outline" onclick='return confirm(@T("Admin.Common.AskToProceed").JsText);' @(hasCredentials ? "" : "disabled='disabled'")
							   href="@Url.Action("CreateWebhook", "PayPalPlus", new { area = Plugin.SystemName })">
								<i class="fa fa-plus"></i>
								<span>@T("Common.AddNew")</span>
							</a>
						}
					</div>
				</div>
				@Html.ValidationMessageFor(model => model.WebhookId)
			</td>
		</tr>
		<tr class="adminSeparator">
			<td colspan="2">
				<div class="admin-config-group">
					<div class="title">
						@Model.ConfigGroups.SafeGet(2)
					</div>
				</div>
			</td>
		</tr>
		<tr>
			<td class="adminTitle">
				@Html.SmartLabelFor(model => model.ThirdPartyPaymentMethods)
			</td>
			<td class="adminData">
				@Html.SettingEditorFor(model => model.ThirdPartyPaymentMethods, @<div>
					@Html.EditorFor(model => model.ThirdPartyPaymentMethods, "SelectList", new { multiple = "multiple", data_tags = "true", selectOptions = Model.AvailableThirdPartyPaymentMethods })
				</div>)
				@Html.ValidationMessageFor(model => model.ThirdPartyPaymentMethods)
			</td>
		</tr>
		<tr>
			<td class="adminTitle">
				@Html.SmartLabelFor(model => model.DisplayPaymentMethodLogo)
			</td>
			<td class="adminData">
				@Html.SettingEditorFor(model => model.DisplayPaymentMethodLogo)
				@Html.ValidationMessageFor(model => model.DisplayPaymentMethodLogo)
			</td>
		</tr>
		<tr>
			<td class="adminTitle">
				@Html.SmartLabelFor(model => model.DisplayPaymentMethodDescription)
			</td>
			<td class="adminData">
				@Html.SettingEditorFor(model => model.DisplayPaymentMethodDescription)
				@Html.ValidationMessageFor(model => model.DisplayPaymentMethodDescription)
			</td>
		</tr>
		<tr>
			<td class="adminTitle">
				@Html.SmartLabelFor(model => model.AdditionalFee)
			</td>
			<td class="adminData">
				@Html.SettingEditorFor(model => model.AdditionalFee, null, new { postfix = Model.PrimaryStoreCurrencyCode })
				@Html.ValidationMessageFor(model => model.AdditionalFee)
			</td>
		</tr>
		<tr>
			<td class="adminTitle">
				@Html.SmartLabelFor(model => model.AdditionalFeePercentage)
			</td>
			<td class="adminData">
				@Html.SettingEditorFor(model => model.AdditionalFeePercentage)
				@Html.ValidationMessageFor(model => model.AdditionalFeePercentage)
			</td>
		</tr>
    </table>
}